home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / lt_lockwindow.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  7KB  |  301 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <exec/memory.h>
  17.  
  18. /*****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22.  
  23. /*****************************************************************************/
  24.  
  25.  
  26. VOID
  27. LTP_DeleteWindowLock(LockNode *Node)
  28. {
  29.     struct Window *Window = Node->Window;
  30.  
  31.     Remove((struct Node *)Node);
  32.  
  33.     if(Window->MinWidth == Window->MaxWidth && Window->MinHeight == Window->MaxHeight && Window->Width == Window->MaxWidth && Window->Height == Window->MaxHeight)
  34.         WindowLimits(Window,Node->MinWidth,Node->MinHeight,Node->MaxWidth,Node->MaxHeight);
  35.  
  36.     EndRequest(&Node->Requester,Window);
  37.  
  38.     if(V39)
  39.         SetWindowPointerA(Window,NULL);
  40.     else
  41.         ClearPointer(Window);
  42.  
  43.     ModifyIDCMP(Window,Node->OldIDCMPFlags);
  44.  
  45.     FreeMem(Node,sizeof(LockNode));
  46. }
  47.  
  48.  
  49. /*****************************************************************************/
  50.  
  51.  
  52. /****** gtlayout.library/LT_LockWindow ******************************************
  53. *
  54. *   NAME
  55. *    LT_LockWindow -- Block user access to a window.
  56. *
  57. *   SYNOPSIS
  58. *    LT_LockWindow(Window);
  59. *                    A0
  60. *
  61. *    VOID LT_LockWindow(struct Window *);
  62. *
  63. *   FUNCTION
  64. *    The window will get a wait mouse pointer attached and a blank
  65. *    Requester, preventing any user gadgets from getting used. The
  66. *    window minimum and maximum sizes are set to the current window
  67. *    size so the user will be unable to resize the window or click
  68. *    on the zoom gadget.
  69. *
  70. *    This routine nests, multiple calls to LT_LockWindow() using the
  71. *    same window will increment a usage counter, so exactly the
  72. *    same number of calls to LT_UnlockWindow() will be required to
  73. *    unlock the window.
  74. *
  75. *   INPUTS
  76. *    Window - Pointer to window structure; passign NULL is harmless.
  77. *
  78. *   RESULT
  79. *    none
  80. *
  81. *   NOTES
  82. *    Do not close the window you have locked unless all the
  83. *    outstanding locks are freed or memory will be lost which
  84. *    can never be reclaimed. Before you close the window,
  85. *    call gtlayout.library/LT_DeleteWindowLock.
  86. *
  87. *   SEE ALSO
  88. *    gtlayout.library/LT_DeleteWindowLock
  89. *
  90. ******************************************************************************
  91. *
  92. */
  93.  
  94. VOID LIBENT
  95. LT_LockWindow(REG(a0) struct Window *window)
  96. {
  97.     if(window)
  98.     {
  99.         LockNode    *lockNode;
  100.         BOOL          found;
  101.  
  102.         found = FALSE;
  103.  
  104.         ObtainSemaphore(<P_LockSemaphore);
  105.  
  106.         SCANLIST(<P_LockList,lockNode)
  107.         {
  108.             if(lockNode->Window == window)
  109.             {
  110.                 lockNode->Count++;
  111.  
  112.                 found = TRUE;
  113.  
  114.                 break;
  115.             }
  116.         }
  117.  
  118.         if(!found)
  119.         {
  120.             if(lockNode = AllocMem(sizeof(LockNode),MEMF_PUBLIC | MEMF_ANY | MEMF_CLEAR))
  121.             {
  122.                 AddTail((struct List *)<P_LockList,(struct Node *)lockNode);
  123.  
  124.                 lockNode->Window        = window;
  125.                 lockNode->OldIDCMPFlags    = window->IDCMPFlags;
  126.                 lockNode->Count            = 1;
  127.                 lockNode->MinWidth        = window->MinWidth;
  128.                 lockNode->MaxWidth        = window->MaxWidth;
  129.                 lockNode->MinHeight        = window->MinHeight;
  130.                 lockNode->MaxHeight        = window->MaxHeight;
  131.  
  132.                 WindowLimits(window,window->Width,window->Height,window->Width,window->Height);
  133.  
  134.                 Request(&lockNode->Requester,window);
  135.  
  136.                 /* Now, this needs a bit of explanation. The requester will shut down
  137.                  * menu processing for this window and still we enable IDCMP_MENUPICK.
  138.                  * This is done in order to avoid setting the IDCMP flags to 0. One
  139.                  * side-effect of setting the IDCMP flags to 0 is that the window message
  140.                  * queue will be cleared, which can be undesirable in certain cases.
  141.                  * With the menu strip blocked IDCMP_MENUPICK cannot do any harm.
  142.                  */
  143.  
  144.                 ModifyIDCMP(window,IDCMP_MENUPICK | (window->IDCMPFlags & (IDCMP_REFRESHWINDOW|IDCMP_CHANGEWINDOW)));
  145.  
  146.                 if(V39)
  147.                 {
  148.                     STATIC const struct TagItem tags[3] =
  149.                     {
  150.                         WA_BusyPointer,        TRUE,
  151.                         WA_PointerDelay,    TRUE,
  152.  
  153.                         TAG_DONE
  154.                     };
  155.  
  156.                     SetWindowPointerA(window,(struct TagItem *)tags);
  157.                 }
  158.                 else
  159.                 {
  160.                     STATIC const UWORD __chip Stopwatch[(1 + 16 + 1) * 2] =
  161.                     {
  162.                         0x0000,0x0000,
  163.  
  164.                         0x0400,0x07C0,
  165.                         0x0000,0x07C0,
  166.                         0x0100,0x0380,
  167.                         0x0000,0x07E0,
  168.                         0x07C0,0x1FF8,
  169.                         0x1FF0,0x3FEC,
  170.                         0x3FF8,0x7FDE,
  171.                         0x3FF8,0x7FBE,
  172.                         0x7FFC,0xFF7F,
  173.                         0x7EFC,0xFFFF,
  174.                         0x7FFC,0xFFFF,
  175.                         0x3FF8,0x7FFE,
  176.                         0x3FF8,0x7FFE,
  177.                         0x1FF0,0x3FFC,
  178.                         0x07C0,0x1FF8,
  179.                         0x0000,0x07E0,
  180.  
  181.                         0x0000,0x0000
  182.                     };
  183.  
  184.                     SetPointer(window,(UWORD *)Stopwatch,16,16,-6,0);
  185.                 }
  186.             }
  187.         }
  188.  
  189.         ReleaseSemaphore(<P_LockSemaphore);
  190.     }
  191. }
  192.  
  193.  
  194. /****************************************************************************/
  195.  
  196.  
  197. /****** gtlayout.library/LT_UnlockWindow ******************************************
  198. *
  199. *   NAME
  200. *    LT_UnlockWindow -- The complement to LT_LockWindow().
  201. *
  202. *   SYNOPSIS
  203. *    LT_UnlockWindow(Window);
  204. *                      A0
  205. *
  206. *    VOID LT_UnlockWindow(struct Window *);
  207. *
  208. *   FUNCTION
  209. *    This routine unlocks a window locked using LT_LockWindow, freeing
  210. *    allocated memory, restoring the window characteristics to their
  211. *    original values.
  212. *
  213. *   INPUTS
  214. *    Window - Pointer to window structure; passing NULL is harmless.
  215. *
  216. *   RESULT
  217. *    none
  218. *
  219. *   SEE ALSO
  220. *    gtlayout.library/LT_LockWindow
  221. *
  222. ******************************************************************************
  223. *
  224. */
  225.  
  226. VOID LIBENT
  227. LT_UnlockWindow(REG(a0) struct Window *window)
  228. {
  229.     if(window)
  230.     {
  231.         LockNode *lockNode;
  232.  
  233.         ObtainSemaphore(<P_LockSemaphore);
  234.  
  235.         SCANLIST(<P_LockList,lockNode)
  236.         {
  237.             if(lockNode->Window == window)
  238.             {
  239.                 if(--lockNode->Count < 1)
  240.                     LTP_DeleteWindowLock(lockNode);
  241.  
  242.                 break;
  243.             }
  244.         }
  245.  
  246.         ReleaseSemaphore(<P_LockSemaphore);
  247.     }
  248. }
  249.  
  250.  
  251. /*****************************************************************************/
  252.  
  253.  
  254. /****** gtlayout.library/LT_DeleteWindowLock ******************************************
  255. *
  256. *   NAME
  257. *    LT_DeleteWindowLock -- Remove all locks from a window
  258. *
  259. *   SYNOPSIS
  260. *    LT_DeleteWindowLock(Window);
  261. *                          A0
  262. *
  263. *    VOID LT_DeleteWindowLock(struct Window *);
  264. *
  265. *   FUNCTION
  266. *    Before closing a locked window you should call this routine
  267. *    which will remove all outstanding locks from it.
  268. *
  269. *   INPUTS
  270. *    Window - Pointer to window structure; passing NULL is
  271. *    harmless.
  272. *
  273. *   RESULT
  274. *    none
  275. *
  276. ******************************************************************************
  277. *
  278. */
  279.  
  280. VOID LIBENT
  281. LT_DeleteWindowLock(REG(a0) struct Window *window)
  282. {
  283.     if(window)
  284.     {
  285.         LockNode *lockNode;
  286.  
  287.         ObtainSemaphore(<P_LockSemaphore);
  288.  
  289.         SCANLIST(<P_LockList,lockNode)
  290.         {
  291.             if(lockNode->Window == window)
  292.             {
  293.                 LTP_DeleteWindowLock(lockNode);
  294.                 break;
  295.             }
  296.         }
  297.  
  298.         ReleaseSemaphore(<P_LockSemaphore);
  299.     }
  300. }
  301.